package service

import (
	"bc/dao"
	"bc/util/library/zstack"
	"fmt"
	"sync"
	"time"
)

type Scene_errlog struct {
	wg sync.WaitGroup
}

func (se *Scene_errlog) Create(errurl string)  {
	//se.wg.Add(1)
	se.CreateLog(errurl)
	//se.wg.Wait()
}

func (se *Scene_errlog) CreateLog (errurl string) {
	var res map[string]interface{}
	for {
		res = zstack.NetWork.GetResults(errurl)
		if _,ok := res["error"];ok {
			fmt.Println(res["error"])
			break
		}
		if _,ok := res["inventory"];ok {
			fmt.Println("创建云主机成功")
			return
		}
	}
	fmt.Println(res["error"])

	var s dao.Zstack_errlog
	e := make(map[string]interface{}, 2)
	e = res["error"].(map[string]interface{})
	if v,ok := e["details"];ok {
		s.Description = v.(string)
	}
	if v,ok := e["code"];ok {
		s.Code = v.(string)
	}
	if v,ok := e["details"];ok {
		s.Details = v.(string)
	}
	s.C_time = time.Now().Unix()
	_ = s.Create()
	//se.wg.Done()
}
